package com.atguigu.yygh.user.service.impl;

import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.mapper.UserInfoMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 林俊伟
 * @create 2021-11-22 10:47
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient>
        implements PatientService {

    //远程调用
    @Autowired
    private DictFeignClient dictFeignClient;

    //获取就诊人列表
    @Override
    public List<Patient> findAllUserId(Long userId) {
        //根据userid查询所有人就诊人信息列表
        QueryWrapper<Patient> wrapper = new QueryWrapper<Patient>();
        List<Patient> patientList = baseMapper.selectList(wrapper);
        //通过远程调用  得到编码对应具体内容 查询数据字典表内容

        patientList.stream().forEach(item ->{
            //其他参数封装
            this.packPatient(item);
        });
        return null;
    }

    //根据id查询就诊人信息
    @Override
    public Patient getPatientId(Long id) {
        Patient patient = baseMapper.selectById(id);

        return this.packPatient(patient);
    }


    //patient对象里面其他参数封装
    private Patient packPatient(Patient patient) {
        //根据证件类型编码  获取证件类型具体值
        String certificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),
                patient.getCertificatesType());

        //联系人证件类型
        String contactsCertificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getContactsCertificatesType());
        //省
        //String provinceString = dictFeignClient.getName(patient.getProvinceCode());
        String provinceString = "ggs";
        //市
        //String cityString = dictFeignClient.getName(patient.getCityCode());
        String cityString = "ggs";
        //区
        //String districtString = dictFeignClient.getName(patient.getDistrictCode());
        String districtString = "ggs";

        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
        return patient;
    }
}
